// pages/fxShopList/fxShopList.js
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: getApp().globalData.imgUrls,
    imgUrl: getApp().globalData.imgUrl,
    value:'' // 上一页带的搜索框val的值
  },


  onLoad: function(options) {
    this.setData({
      value: options.val || ''
    })
  },


  onShow: function() {
    this.getFxShopList()
  },
  addRecommend(e) {
    util.API('pyapi/add_my_chose_goods', {
      goods_id: e.currentTarget.dataset.goods_id
    }, 'application/x-www-form-urlencoded').then(res => {
      let {
        code,
        msg
      } = res
      wx.showToast({
        title: msg + '',
        icon: 'none'
      })
    })
  },
  jumpDetails(e) {
    console.log(getApp().globalData.member_id)
    wx.navigateTo({
      url: `/pages/shopDetails/shopDetails?goods_id=${e.currentTarget.dataset.item.goods_id}&parent_id=${getApp().globalData.member_id}`,
    })
  },
  changeFenLei() { // 列表样式切换
    this.setData({
      isLieBiao: !this.data.isLieBiao
    })
  },
  jumpSearch(){
    wx.navigateTo({
      url: '/pages/Search/Search?isFenXiao=true',
    })
  },
  getFxShopList() {
    util.API('pyapi/distribute_goods_list', {
      value: this.data.value,
    }, 'application/x-www-form-urlencoded').then(res => {
      let {
        code,
        data,
        member_lv
      } = res
      if (code === 200) {
        data = data.map(item => {
          item.goods__goods_cover = item.goods__goods_cover.split(',')[0]
          return item
        })
        this.setData({
          list: data
        })
      }
    })
  }
})